import random
from multiprocessing import Pool


def compute(n):
    '''计算100万个1到100之间的随机数的和'''
    total = sum([random.randint(1,100) for i in range(1000000)])
    return total

def main():
    # 构建了一个进程池，进程数量是固定的
    pool = Pool(processes=8)
    result = pool.map(compute,range(8))
    print(result)

if __name__ == '__main__':
    main()